package GUI;


import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class GuiServer extends JFrame {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private MainPanel mainPanel;
	private int sizeHeight = 400;															//dimensioni della finestra
	private int sizeWidth = 600;

	public GuiServer(){
		super("Server Mouse");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		int height = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();		//dimensioni dello schermo
		int width = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
		this.setLocation(width/2-sizeWidth/2, height/2-sizeHeight/2);
		setSize(sizeWidth,sizeHeight);
		this.setResizable(false); 
		
	}

	
	/* riceve un messaggio da visualizzare nella Gui, nel nostro caso riceve in ingresso l'indirizzo ip dell'host
	 * Inizializza la gui e mostra a video il messaggio
	 * */
	public void  init(final String mex){
		SwingUtilities.invokeLater(new Runnable(){
			
			@Override
			public void run() {
				mainPanel = new MainPanel();
				JTextArea textIp = new JTextArea();
				JLabel intro = new JLabel();
				Font font = new Font(Font.MONOSPACED, Font.BOLD, 18);
				intro.setText("Scegli uno tra questi ip. Buon lavoro!");
				intro.setForeground(Color.RED);
				intro.setSize(sizeWidth, 40);
				intro.setHorizontalAlignment(JLabel.CENTER);
				intro.setFont(font);
				
				
				textIp.setEditable(false);
				textIp.setOpaque(false);
				textIp.setForeground(Color.RED);
				textIp.setSize(sizeWidth, 40);
				textIp.setFont(font);
				textIp.setToolTipText("Ip Host");
				textIp.setText(mex);
				textIp.setAutoscrolls(true);
				
				
				
				GuiServer gui = new GuiServer();
				mainPanel.setLayout(new GridLayout(3,1));
				mainPanel.add(intro);
				mainPanel.add(textIp);
				gui.add(mainPanel);
				gui.setVisible(true);
				
			}
		});
	}
	
	
}
